package vlms.controller;

import java.io.IOException;
import java.rmi.RemoteException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import vlms.bean.*;
import vlms.service.VLMSServiceProxy;
import wrapper.CartMovie;



/**
 * Servlet implementation class Checkout
 */
public class Checkout extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Checkout() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub

	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		String message = null; 
		String destination = "/home.jsp";
		HttpSession session = request.getSession();
		Person oPerson = (Person) session.getAttribute("Person");
		String sPersonId = String.valueOf(oPerson.getPersonid());
		
		try
		 {
			 VLMSServiceProxy proxy = new VLMSServiceProxy();
			 proxy.validateCart(sPersonId);
			
			 CartMovie[] aCartMovie = proxy.viewCart(sPersonId);
			 
			 request.setAttribute("CartMovie", aCartMovie);
			
			destination = "/confirmation.jsp";
			
		 }
		 catch(RemoteException re)
		 {
			 destination = "/ViewCart";
			 request.setAttribute("message", re.getMessage());
			 re.printStackTrace();
		 }
		
		
		
		RequestDispatcher rd = this.getServletContext().getRequestDispatcher(destination);
		rd.forward(request, response);
		
		
	}	

}
